﻿using ReservationModule.Classes;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ReservationModule
{
    public partial class RetrieveAccount : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            Session["Login"] = Session["Login"];
            if (Session["Login"] == "false" || Session["Login"] == null)
            {
                Response.Redirect("Reject.aspx");
            }

            if (Session["StaffType"] != "Administrator")
            {
                Response.Redirect("Reject.aspx");
            }

        }

        protected void btnRetrieve_Click(object sender, EventArgs e)
        {
            string staffID = tbxStaffID.Text;

            UserAccount a = DBManager.GetAccountByStaffID(staffID);
            if (a != null)
            {
                tbxID.Text = a.StaffID1;
                tbxPass.Text = a.Password1;
                DDL.Text = a.StaffType1;
                tbxNRIC.Text = a.StaffNRIC1;
            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            string staffID = tbxID.Text;
            string password = tbxPass.Text;
            string staffType = DDL.Text;
            string staffNRIC = tbxNRIC.Text;

            UserAccount u = new UserAccount() { StaffID1 = staffID, Password1 = password, StaffType1 = staffType, StaffNRIC1 = staffNRIC };
            int useraccount = DBManager.UpdateUserAccount(u);

            Response.Redirect("UpdateAccountSuccessful.aspx?");
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int delete = DBManager.DeleteUserAccount(tbxStaffID.Text);
            int delete1 = DBManager.DeleteUserAccount1(tbxStaffNRIC.Text);
            Response.Redirect("DeleteAccountSuccessful.aspx?");
        }

        protected void btnRetrieve2_Click(object sender, EventArgs e)
        {
            string staffNRIC = tbxStaffNRIC.Text;

            UserAccount a = DBManager.GetAccountByStaffNRIC(staffNRIC);
            if (a != null)
            {
                tbxID.Text = a.StaffID1;
                tbxPass.Text = a.Password1;
                DDL.Text = a.StaffType1;
                tbxNRIC.Text = a.StaffNRIC1;
            }

        }
    }
}